package it.uniroma2.art.owlart.langsearch.analysis;

import java.io.Reader;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.lucene.analysis.standard.StandardTokenizer;

public class SynonymAnalyzer extends Analyzer {
	
	private SynonymEngine engine;
	
	public SynonymAnalyzer(SynonymEngine engine) {
		this.engine = engine;
	}
	
	public TokenStream tokenStream(String fieldName, Reader reader) {
		TokenStream result = new SynonymFilter(
				new StopFilter(
						new LowerCaseFilter(
								new StandardFilter(
										new StandardTokenizer(reader)
								)
						),
						StandardAnalyzer.STOP_WORDS
				),
				engine
		);
		return result;
	}
}
